package neurons;

public class Function implements FunctionInterface {

	private Double coeff;
	private Double epsilon = 0.25;
	private boolean correctionSlope;

	public Function() {
		coeff = Math.random();

	}

	@Override
	public SignalInterface transform(SignalInterface signal) {
		if (signal.getData() > coeff) {
			return new Signal(1.0);
		}
		return new NullSignal();
	}

	@Override
	public void adaptCoeff(Double delta) {
		System.out.println("previous coeff : " + coeff);
		if (delta > 0) {
			boolean newCorrectionSlope = true;
			if (!correctionSlope == newCorrectionSlope) {
				epsilon /= 2;
			}
			coeff += epsilon;
			correctionSlope = newCorrectionSlope;

		} else {
			boolean newCorrectionSlope = false;
			if (!correctionSlope == newCorrectionSlope) {
				epsilon /= 2;
			}
			coeff -= epsilon;
			correctionSlope = newCorrectionSlope;

		}
System.out.println("Correcting of espilon : "+epsilon);
		System.out.println("new coeff : " + coeff);
	}

}
